home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
cmln0186.arc
/
CROSSTH1.LTG
< prev
next >
Wrap
Text File
|
1986-12-20
|
2KB
|
69 lines
Listing 1.
PPL code for the concurrent Shell-Metzner sort.
PROCEDURE ShellSort(List : array of your data; Num : integer)
-- Procedure to shell sort an array of List[]
-- Num is the number of elements to be sorted
BEGIN
INITIALIZE: Offset = Num
LOOP <One>
BEGIN IF Offset <= 1 THEN EXIT <One> END IF
INITIALIZE: Offset /= 2 -- Integer division
LOOP <TWO>
BEGIN
INITIALIZE: InOrder = TRUE
LOOP <SWAP_CYCLE>
BEGIN For J = 1 to Num - Offset
I = J + Offset
-- Start concurrent procedure with priority J
-- Compare() will compare and swap elements if needed
-- setting InOrder = FALSE if elements were swapped
StartProcedure(Compare(List[J],List[J]),J,Signal[J])
END LOOP <SWAP_CYCLE>
TERMINATE: Wait for pending Signals
If InOrder THEN EXIT <TWO> END IF
END LOOP <TWO>
TERMINATE: None
END LOOP <ONE>
TERMINATE: None
END ShellSort
PPL code for the concurrent list insertion-sort
PROCEDURE InsertSort(List : array[1..NumCPU] of array of your data;
MoreData : array of your data;
Ptr : array of pointer to your data;
NumInList, NumAdded, NumCPU : integer)
-- NumCPU = number of CPUs and sub-lists
-- NumInList = current list size
-- NumAdded = number of added list elements
VAR Done : array[1..NumAdded] of boolean
BusyCPU : array[1..NumCPU] of boolean
BEGIN
INITIALIZE: Set elements of Done and BusyCPU arrays to FALSE
All_Done = FALSE; Priority = 1
LOOP <OUTER>
BEGIN IF All_Done THEN EXIT <OUTER> END IF
INITIALIZE: All_Done = TRUE
LOOP <INNER>
BEGIN For i = 1 to NumAdded
j = index of MoreData[i] from Search Table
IF Signal[j] THEN BusyCPU[j] = FALSE ELSE BusyCPU[j] = TRUE END
IF NOT BusyCPU[j]
THEN StartProcedure(Insert(MoreData[i],j),Priority,Signal[j])
Done[i] = TRUE;
ELSE All_Done = FALSE END IF
END LOOP <INNER>
TERMINATE: None
END LOOP <OUTER>
TERMINATE: None
END InsertSort